home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap01 / howto03 / win16tb.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-29  |  29.6 KB  |  903 lines

  1. unit Win16tb;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes , WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, ShellAPI;
  8.  
  9. type
  10.   TCCTaskBarForm = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     BitBtn3: TBitBtn;
  15.     BitBtn4: TBitBtn;
  16.     BitBtn5: TBitBtn;
  17.     BitBtn6: TBitBtn;
  18.     BitBtn7: TBitBtn;
  19.     OpenDialog1: TOpenDialog;
  20.     PopupMenu1: TPopupMenu;
  21.     StartAsIcon1: TMenuItem;
  22.     AddFile1: TMenuItem;
  23.     ShowOnBottom1: TMenuItem;
  24.     ShowOnTop1: TMenuItem;
  25.     PopupMenu2: TPopupMenu;
  26.     NewFile1: TMenuItem;
  27.     MoveUp1: TMenuItem;
  28.     MoveDown1: TMenuItem;
  29.     Delete1: TMenuItem;
  30.     procedure BitBtn2Click(Sender: TObject);
  31.     procedure FormCreate(Sender: TObject);
  32.     procedure BitBtn1Click(Sender: TObject);
  33.     procedure FormDestroy(Sender: TObject);
  34.     procedure BitBtn5Click(Sender: TObject);
  35.     procedure BitBtn6Click(Sender: TObject);
  36.     procedure BitBtn7Click(Sender: TObject);
  37.     procedure BitBtn3Click(Sender: TObject);
  38.     procedure BitBtn4Click(Sender: TObject);
  39.     procedure StartAsIcon1Click(Sender: TObject);
  40.     procedure ShowOnBottom1Click(Sender: TObject);
  41.     procedure ShowOnTop1Click(Sender: TObject);
  42.     procedure AddFile1Click(Sender: TObject);
  43.     procedure NewFile1Click(Sender: TObject);
  44.     procedure Delete1Click(Sender: TObject);
  45.     procedure MoveUp1Click(Sender: TObject);
  46.     procedure MoveDown1Click(Sender: TObject);
  47.     procedure BitBtn5MouseDown(Sender: TObject; Button: TMouseButton;
  48.       Shift: TShiftState; X, Y: Integer);
  49.     procedure BitBtn6MouseDown(Sender: TObject; Button: TMouseButton;
  50.       Shift: TShiftState; X, Y: Integer);
  51.     procedure BitBtn7MouseDown(Sender: TObject; Button: TMouseButton;
  52.       Shift: TShiftState; X, Y: Integer);
  53.     procedure BitBtn5MouseUp(Sender: TObject; Button: TMouseButton;
  54.       Shift: TShiftState; X, Y: Integer);
  55.     procedure BitBtn6MouseUp(Sender: TObject; Button: TMouseButton;
  56.       Shift: TShiftState; X, Y: Integer);
  57.     procedure BitBtn7MouseUp(Sender: TObject; Button: TMouseButton;
  58.       Shift: TShiftState; X, Y: Integer);
  59.   private
  60.     { Private declarations }
  61.   public
  62.     { Public declarations }
  63.     procedure ReadTheTaskBarIniFile;     { This reads in the program data     }
  64.     procedure WriteTheTaskBarIniFile;    { This writes out the program data   }
  65.     procedure SetUpTheTaskBar;           { This sets up the icon/data array   }
  66.     procedure DeleteTasksFrom( TheTask : Integer ); { Fiddle w record array   }
  67.     procedure ReplaceFile( CurrentSelection : Integer ); { Replace file       }
  68.   end;                         { and puts the first 3 into view     }
  69.   PTBRecord = ^TBRecord;                      { Define pointer type }
  70.   TBRecord = record                          { Define record type  }
  71.     TheName : String;                         { Holds program name  }
  72.     TheBitmap : TBitmap;                      { Holds bitmpd icon   }
  73.     TheIcon   : TIcon;
  74.   end;
  75.   PTBArray = array[ 1 .. 255 ] of PTBRecord;  { Working data array  }
  76.  
  77. var
  78.   CCTaskBarForm: TCCTaskBarForm;
  79.   ThePTBArray        : PTBArray; { This holds the data array from INI }
  80.   TotalTaskEntries   : Integer;  { This is the total items to use     }
  81.   CurrentTaskPointer : Integer;  { This is the position to start disp }
  82.   DeleteMode         : Boolean;  { This is a flag indicating deletion }
  83.   ShowPosition       : Integer;  { This handles staring at top/bottom }
  84.   StartingState      : Integer;  { This handles normal/icon startup   }
  85.   TotalTaskPointers  : Integer;  { This keeps track of the total tasks}
  86.   CurrentTaksPointer : Integer;  { This holds current task to run     }
  87.   ActiveButton       : TBitBtn;  { This holds the identity of the btn }
  88.   SaveStartupDir     : String;   { This holds the starting directory  }
  89. implementation
  90.  
  91. {$R *.DFM}
  92.  
  93. uses
  94.   IniFiles ;  { Ini file handler unit       }
  95.  
  96. const
  97.  
  98.   TaskBarIniFileName = 'CCTSKBAR.INI';  { Make this a constant to save stack space }
  99.  
  100.  
  101. function ShellExec(const PathStr, CmdStr, DirStr: string;
  102.   PrintIt: boolean; Show: word; Wait: boolean): boolean;
  103. var
  104.   Inst: THandle;
  105.   Path, CmdLine, Dir: PChar;
  106.   Op: array[0..5] of Char;
  107. begin
  108.   if PrintIt then StrPCopy(Op, 'print') else StrPCopy(Op, 'open');
  109.   { Get memory for PChars }
  110.   GetMem(Path, Length(PathStr)+1);
  111.   GetMem(CmdLine, Length(CmdStr)+1);
  112.   GetMem(Dir, Length(DirStr)+1);
  113.   try
  114.     { Copy strings to PChars }
  115.     StrPCopy(Path, PathStr);
  116.     StrPCopy(CmdLine, CmdStr);
  117.     StrPCopy(Dir, DirStr);
  118.     { Execute file }
  119.     Inst := ShellExecute(0, Op, Path, CmdLine, Dir, Show);
  120.     { If 32 or less, an error occurred }
  121.     if Inst <= 32 then Result := False else
  122.     begin
  123.       Result := True;
  124.     end;
  125.   finally
  126.     { Ensure memory is freed }
  127.     FreeMem(Path, Length(PathStr)+1);
  128.     FreeMem(CmdLine, Length(CmdStr)+1);
  129.     FreeMem(Dir, Length(DirStr)+1);
  130.   end;
  131. end;
  132.  
  133. procedure TCCTaskBarForm.ReplaceFile( CurrentSelection : Integer );
  134. var ThePChar   : PChar;
  135.     TheOtherPChar ,
  136.     TheResultPChar : PChar;
  137.     TheExt : String;
  138. begin
  139.   GetMem( ThePChar , 255 );
  140.   if OpenDialog1.Execute then
  141.   begin
  142.     with ThePTBArray[ CurrentSelection ]^ do
  143.     begin
  144.       TheName := OpenDialog1.Filename;
  145.       TheExt := Uppercase( ExtractFileExt( TheName ));
  146.       if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  147.           ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  148.       begin
  149.         GetMem( TheOtherPChar , 255 );
  150.         GetMem( TheResultPChar , 255 );
  151.         StrPCopy( ThePChar, TheName );
  152.         StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  153.         if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  154.         begin
  155.           TheIcon.Free;
  156.           TheIcon := TIcon.Create;
  157.           TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  158.         end
  159.         else
  160.         begin
  161.           MessageDlg( 'No Application Registered for this File Type!',mtError,[mbok],0);
  162.           TheIcon.Handle := 0;
  163.         end;
  164.         FreeMem( TheOtherPChar , 255 );
  165.         FreeMem( TheResultPChar , 255 );
  166.       end
  167.       else
  168.       begin
  169.         StrPCopy( ThePChar , TheName );
  170.         TheIcon.Free;
  171.         TheIcon := TIcon.Create;
  172.         TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  173.       end;
  174.       if TheIcon.Handle <> 0 then
  175.       begin
  176.         TheBitmap.Canvas.Draw( 1,1,TheIcon );
  177.       end
  178.       else
  179.       begin
  180.         TheBitmap.LoadFromFile( SaveStartupDir +'\Default.bmp' );
  181.       end;
  182.     end;
  183.     SetupTheTaskBar;
  184.   end;
  185.   FreeMem( ThePChar , 255 );
  186. end;
  187.  
  188. procedure TCCTaskBarForm.DeleteTasksFrom( TheTask : Integer );
  189. var Counter_1 : Integer;
  190. begin
  191.   if TheTask = TotalTaskEntries then
  192.   begin
  193.     ThePTBArray[ TheTask ]^.TheName := '';
  194.     ThePTBArray[ TheTask ]^.TheBitmap.LoadFromFile( SaveStartupDir + '\NOFILE.BMP' );
  195.     TotalTaskEntries := TotalTaskEntries - 1;
  196.   end
  197.   else
  198.   begin
  199.     for Counter_1 := TheTask + 1 to TotalTaskEntries do
  200.     begin
  201.       with ThePTBArray[ Counter_1 ]^ do
  202.       begin
  203.         ThePTBArray[ Counter_1 - 1 ]^.TheName := TheName;
  204.         ThePTBArray[ Counter_1 - 1 ]^.TheBitmap.Canvas.Draw( 0 , 0 , TheIcon );
  205.       end;
  206.     end;
  207.     if TotalTaskEntries > 3 then
  208.     begin
  209.       ThePTBArray[ TotalTaskEntries ]^.TheBitmap.Free;
  210.       ThePTBArray[ TotalTaskEntries ]^.TheIcon.Free;
  211.       Dispose( ThePTBArray[ TotalTaskEntries ] );
  212.       TotalTaskEntries := TotalTaskEntries - 1;
  213.     end
  214.     else
  215.     begin
  216.       ThePTBArray[ TotalTaskEntries ]^.TheName := '';
  217.       ThePTBArray[ TotalTaskEntries ]^.TheBitmap.LoadFromFile( SaveStartupDir + '\NOFILE.BMP' );
  218.       TotalTaskEntries := TotalTaskEntries - 1;
  219.     end;
  220.   end;
  221. end;
  222.  
  223. procedure TCCTaskBarForm.SetupTheTaskBar;
  224. var Counter_1      : Integer;
  225.     WorkingPointer : Integer;
  226. begin
  227.   if TotalTaskEntries < 3 then
  228.   begin
  229.     case TotalTaskEntries of
  230.       0 : begin
  231.             BitBtn5.Caption := 'No File';
  232.             BitBtn5.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  233.             BitBtn6.Caption := 'No File';
  234.             BitBtn6.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  235.             BitBtn7.Caption := 'No File';
  236.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  237.           end;
  238.       1 : begin
  239.             BitBtn6.Caption := 'No File';
  240.             BitBtn6.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  241.             BitBtn7.Caption := 'No File';
  242.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  243.           end;
  244.       2 : begin
  245.             BitBtn7.Caption := 'No File';
  246.             BitBtn7.Glyph.LoadFromfile( SaveStartupDir + '\NoFile.BMP' );
  247.           end;
  248.     end;
  249.   end;
  250.   WorkingPointer := CurrentTaskPointer - 1;
  251.   for Counter_1 := 1 to 3 do
  252.   begin
  253.     WorkingPointer := WorkingPointer + 1;
  254.     if WorkingPointer > TotalTaskEntries then break;
  255.     with ThePTBArray[ WorkingPointer ]^ do
  256.     begin
  257.       case Counter_1 of
  258.         1 : begin
  259.               BitBtn5.Caption := ExtractFileName( TheName );
  260.               BitBtn5.Glyph := TheBitmap;
  261.             end;
  262.         2 : begin
  263.               BitBtn6.Caption := ExtractFileName( TheName );
  264.               BitBtn6.Glyph := TheBitmap;
  265.             end;
  266.         3 : begin
  267.               BitBtn7.Caption := ExtractFileName( TheName );
  268.               BitBtn7.Glyph := TheBitmap;
  269.             end;
  270.       end;
  271.     end;
  272.   end;
  273.   if TotalTaskEntries > 3 then BitBtn4.Enabled := true
  274.    else BitBtn4.Enabled := false;
  275.   if CurrentTaskPointer > 1 then BitBtn3.Enabled := true
  276.    else BitBtn3.Enabled := false;
  277. end;
  278.  
  279. { This procedure reads in the configuration from an INI file }
  280. procedure TCCTaskBarForm.ReadTheTaskBarIniFile;
  281. var
  282.    { The excellent TIniFile object handles the complexity of Windows INI files! }
  283.    TheIniFile : TIniFile;
  284.    TempString,
  285.    TempString2 : String;
  286.    Counter_1  : Integer;
  287.    ThePChar   : PChar;
  288.    TheFileCounterString : String;
  289.  
  290. begin
  291.   GetMem( ThePchar , 255 );
  292.   CurrentTaskPointer := 1;
  293.   { Combine assignfile and reset into one call with create }
  294.   TheIniFile := TIniFile.Create( TaskBarIniFileName );
  295.   { Use a try block to make sure the ini file is closed by free call }
  296.   try
  297.     { Use the Tinifile object's read methods to get the configuration data }
  298.     with TheIniFile do
  299.     begin
  300.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  301.       TotalTaskEntries := ReadInteger( 'Setup', 'TotalEntries', 0 );
  302.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  303.       ShowPosition := ReadInteger( 'Setup', 'StartPosition', 0 );
  304.       { Use readinteger to get the total taskbar entries, with default of 0 for new file }
  305.       StartingState := ReadInteger( 'Setup', 'StartState', 1 );
  306.       if TotalTaskEntries = 0 then
  307.       begin
  308.         GetWindowsDirectory( ThePChar , 255 );
  309.         TempString2 := StrPas( ThePChar );
  310.         TempString := TempString2;
  311.         if FileExists( TempString + '\PBRUSH.EXE' ) then
  312.         begin
  313.           New( ThePTBArray[ 1 ] );
  314.           with ThePTBArray[ 1 ]^ do
  315.           begin
  316.             TempString := TempString + '\PBRUSH.EXE';
  317.             TheName := TempString;
  318.             TheBitmap := TBitmap.Create;
  319.             TheBitmap.Height := 32;
  320.             TheBitmap.Width := 32;
  321.             StrPCopy( ThePChar , TempString );
  322.             TheIcon := TIcon.Create;
  323.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  324.             if TheIcon.Handle <> 0 then
  325.             begin
  326.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  327.             end
  328.             else
  329.             begin
  330.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  331.             end;
  332.           end;
  333.           TotalTaskEntries := 1;
  334.         end;
  335.         TempString := TempString2;
  336.         if FileExists( TempString + '\WRITE.EXE' ) then
  337.         begin
  338.           New( ThePTBArray[ 2 ] );
  339.           with ThePTBArray[ 2 ]^ do
  340.           begin
  341.             TempString := TempString + '\WRITE.EXE';
  342.             TheName := TempString;
  343.             TheBitmap := TBitmap.Create;
  344.             TheBitmap.Height := 32;
  345.             TheBitmap.Width := 32;
  346.             StrPCopy( ThePChar , TempString );
  347.             TheIcon := TIcon.Create;
  348.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  349.             if TheIcon.Handle <> 0 then
  350.             begin
  351.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  352.             end
  353.             else
  354.             begin
  355.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  356.             end;
  357.             TotalTaskEntries := TotalTaskEntries + 1;
  358.           end;
  359.         end;
  360.         TempString := TempString2;
  361.         if FileExists( TempString + '\CONTROL.EXE' ) then
  362.         begin
  363.           New( ThePTBArray[ 3 ] );
  364.           with ThePTBArray[ 3 ]^ do
  365.           begin
  366.             TempString := TempString + '\CONTROL.EXE';
  367.             TheName := TempString;
  368.             TheBitmap := TBitmap.Create;
  369.             TheBitmap.Height := 32;
  370.             TheBitmap.Width := 32;
  371.             StrPCopy( ThePChar , TempString );
  372.             TheIcon := TIcon.Create;
  373.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  374.             if TheIcon.Handle <> 0 then
  375.             begin
  376.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  377.             end
  378.             else
  379.             begin
  380.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  381.             end;
  382.           end;
  383.           TotalTaskEntries := TotalTaskEntries + 1;
  384.         end;
  385.       end
  386.       else
  387.       begin
  388.         for Counter_1 := 1 to TotalTaskEntries do
  389.         begin
  390.           TheFileCounterString := 'FileNo_' + IntToStr( Counter_1 );
  391.           TempString := ReadString( 'FileList', TheFileCounterString, '' );
  392.           New( ThePTBArray[ Counter_1 ] );
  393.           with ThePTBArray[ Counter_1 ]^ do
  394.           begin
  395.             TheName := TempString;
  396.             TheBitmap := TBitmap.Create;
  397.             TheBitmap.Height := 32;
  398.             TheBitmap.Width := 32;
  399.             StrPCopy( ThePChar , TempString );
  400.             TheIcon := TIcon.Create;
  401.             TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  402.             if TheIcon.Handle <> 0 then
  403.             begin
  404.               TheBitmap.Canvas.Draw( 1,1,TheIcon );
  405.             end
  406.             else
  407.             begin
  408.               TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  409.             end;
  410.           end;
  411.         end;
  412.       end;
  413.     end;
  414.   finally
  415.     { Regardless of success or failure, free the TIniFile object }
  416.     TheIniFile.Free;
  417.     FreeMem( ThePChar , 255 );
  418.   end;
  419. end;
  420.  
  421. { This procedure writes out the configuration to an INI file }
  422. procedure TCCTaskBarForm.WriteTheTaskBarIniFile;
  423. var
  424.    { Again use the very useful TIniFile object to encapsulate Windows INI files }
  425.    TheIniFile : TIniFile;
  426.    TempString : String;
  427.    Counter_1 : Integer;
  428. begin
  429.   { Combine an AssignFile and Reset call into the create method }
  430.   TheIniFile := TIniFile.Create( TaskBarIniFileName );
  431.   try
  432.     { Use the TIniFile object's methods to write out the data }
  433.     with TheIniFile do
  434.     begin
  435.       { Use writeinteger to send the total entries in the program }
  436.       WriteInteger( 'Setup' , 'TotalEntries' , TotalTaskEntries );
  437.       { Use writeinteger to send the total entries in the program }
  438.       WriteInteger( 'Setup' , 'StartPosition' , ShowPosition );
  439.       { Use writeinteger to send the total entries in the program }
  440.       WriteInteger( 'Setup' , 'StartState' , StartingState );
  441.       for Counter_1 := 1 to TotalTaskEntries do
  442.       begin
  443.         TempString := 'FileNo_' + IntToStr( Counter_1 );
  444.         { Use writestring to send the Working directory for image files }
  445.         WriteString( 'FileList' , TempString , ThePTBArray[ Counter_1 ]^.TheName );
  446.       end;
  447.     end;
  448.   finally
  449.     { Regardless of above calls, free the TIniFile object }
  450.     TheIniFile.Free;
  451.   end;
  452. end;
  453.  
  454.  
  455. { This was written by Delphi; use it to simply close the form since }
  456. { the INI file is updated continually                               }
  457. procedure TCCTaskBarForm.BitBtn2Click(Sender: TObject);
  458. begin
  459.   { Go bye bye }
  460.   close;
  461. end;
  462.  
  463. { This was written by Delphi; use it to size the form on the bottom and }
  464. { place the buttons according to screen size. Then read in the INI file }
  465. { and set up the data lists and set the first three buttons (or less.)  }
  466. procedure TCCTaskBarForm.FormCreate(Sender: TObject);
  467. var WorkingSpace    ,              { This is the basic area to work with  }
  468.     WorkingDivision ,              { If more than enough use this for lng }
  469.     WorkingLength     : Integer;   { If less than enough use this for len }
  470. begin
  471.   GetDir( 0 , SaveStartupDir );
  472.   { Set to the screen's width }
  473.   Width := Screen.Width - 2;
  474.   { Move to the left edge }
  475.   Left := 1;
  476.   { Set the exit button's position }
  477.   BitBtn2.Left := Screen.Width - 145;
  478.   { Set the right scroll button's position }
  479.   BitBtn4.Left := BitBtn2.Left - 45;
  480.   { Determine how much room is left }
  481.   WorkingSpace := BitBtn4.left - 200;
  482.   { if plenty of room spread out }
  483.   if WorkingSpace >= 575 then
  484.   begin
  485.     { Divide into 3 chunks }
  486.     WorkingDivision := WorkingSpace div 3;
  487.     { Start at the left edge }
  488.     BitBtn5.Left := 200;
  489.     { Move across one }
  490.     BitBtn6.Left := 210 + WorkingDivision;
  491.     { Move across two }
  492.     BitBtn7.Left := 220 + WorkingDivision * 2;
  493.   end
  494.   else
  495.   begin { Narrow the buttons down to fit the available space }
  496.     { Divide into 3 chunks }
  497.     WorkingLength := ( WorkingSpace div 3 );
  498.     { Set the button widths to less than the chunks }
  499.     BitBtn5.Width := WorkingLength - 15;
  500.     BitBtn6.Width := WorkingLength - 15;
  501.     BitBtn7.Width := WorkingLength - 15;
  502.     { Start at the left edge }
  503.     BitBtn5.left := 200;
  504.     { Move across one }
  505.     BitBtn6.Left := 210 + WorkingLength;
  506.     { Move across two }
  507.     BitBtn7.Left := 220 + ( WorkingLength * 2 );
  508.   end;
  509.   { Read in the INI file data and initialize }
  510.   ReadTheTaskBarIniFile;
  511.   { Move to the bottom of the screen }
  512.   if ShowPosition = 0 then Top := Screen.Height - 90 else Top := 1;
  513.   if StartingState = 0 then
  514.   begin
  515.     WindowState := wsMinimized;
  516.     StartAsIcon1.Checked := true;
  517.   end
  518.   else
  519.   begin
  520.     windowstate := wsnormal;
  521.     StartAsIcon1.Checked := false;
  522.   end;
  523.   SetUpTheTaskBar;
  524.   CurrentTaskPointer := 1;
  525. end;
  526.  
  527. { Delphi wrote this; use it to minimize the form so icons can be seen }
  528. { (since have put in an (invisible) system box, double clicking the   }
  529. { icon will bring back up to max state.)                              }
  530. procedure TCCTaskBarForm.BitBtn1Click(Sender: TObject);
  531. begin
  532.   { Turn into an icon for user friendliness }
  533.   WindowState := wsMinimized;
  534. end;
  535.  
  536. { Delphi wrote this; use it to clean up the memory used by the records array }
  537. procedure TCCTaskBarForm.FormDestroy(Sender: TObject);
  538. var Counter_1 : Integer;
  539. begin
  540.   for Counter_1 := 1 to TotalTaskEntries do
  541.   begin
  542.     ThePTBarray[ Counter_1 ]^.TheBitmap.Free;
  543.     ThePTBArray[ Counter_1 ]^.TheIcon.Free;
  544.     Dispose( ThePTBArray[ Counter_1 ] );
  545.   end;
  546. end;
  547.  
  548. procedure TCCTaskBarForm.BitBtn5Click(Sender: TObject);
  549. var
  550.   TheActiveWindow    : HWnd;
  551.   TheFileNametoShell : String;
  552.   TheWindowList      : Pointer;
  553. begin
  554.   if TotalTaskEntries = 0 then exit;
  555.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer ]^.Thename;
  556.   if TheFileNametoShell = '' then exit;
  557.   TheWindowList := DisableTaskWindows( 0 );
  558.   TheActiveWindow := GetActiveWindow;
  559.   try
  560.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  561.       SW_SHOWNORMAL , false ) then
  562.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  563.   finally
  564.     EnableTaskWindows( TheWindowList );
  565.     SetActiveWindow( TheActiveWindow );
  566.   end;
  567. end;
  568.  
  569. procedure TCCTaskBarForm.BitBtn6Click(Sender: TObject);
  570. var
  571.   TheActiveWindow    : HWnd;
  572.   TheFileNametoShell : String;
  573.   TheWindowList      : Pointer;
  574. begin
  575.   if CurrentTaskPointer + 1 > TotalTaskEntries then Exit;
  576.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer + 1 ]^.Thename;
  577.   TheWindowList := DisableTaskWindows( 0 );
  578.   TheActiveWindow := GetActiveWindow;
  579.   try
  580.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  581.       SW_SHOWNORMAL , false ) then
  582.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  583.   finally
  584.     EnableTaskWindows( TheWindowList );
  585.     SetActiveWindow( TheActiveWindow );
  586.   end;
  587. end;
  588.  
  589. procedure TCCTaskBarForm.BitBtn7Click(Sender: TObject);
  590. var
  591.   TheActiveWindow    : HWnd;
  592.   TheFileNametoShell : String;
  593.   TheWindowList      : Pointer;
  594. begin
  595.   if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  596.   TheFileNametoShell := ThePTBArray[ CurrentTaskPointer + 2 ]^.Thename;
  597.   TheWindowList := DisableTaskWindows( 0 );
  598.   TheActiveWindow := GetActiveWindow;
  599.   try
  600.     if not ShellExec( TheFileNametoShell , '' , '', false ,
  601.       SW_SHOWNORMAL , false ) then
  602.     MessageDlg('Could not Execute Task!', mtInformation, [mbOK], 0);
  603.   finally
  604.     EnableTaskWindows( TheWindowList );
  605.     SetActiveWindow( TheActiveWindow );
  606.   end;
  607. end;
  608.  
  609. { Delphi wrote this; use it to move the button list one place left }
  610. procedure TCCTaskBarForm.BitBtn3Click(Sender: TObject);
  611. begin
  612.   if CurrentTaskPointer = 1 then exit else
  613.   begin
  614.     CurrentTaskPointer := CurrentTaskPointer - 1;
  615.     SetUpTheTaskBar;
  616.     if CurrentTaskPointer = 1 then BitBtn3.Enabled := false;
  617.     if CurrentTaskPointer < ( TotalTaskEntries - 2 ) then
  618.      BitBtn4.Enabled := true;
  619.   end;
  620. end;
  621.  
  622. { Delphi wrote this; use it to move the button list one place right }
  623. procedure TCCTaskBarForm.BitBtn4Click(Sender: TObject);
  624. begin
  625.   if CurrentTaskPointer >= ( TotalTaskEntries - 2 ) then exit else
  626.   begin
  627.     CurrentTaskPointer := CurrentTaskPointer + 1;
  628.     SetUpTheTaskBar;
  629.     if CurrentTaskPointer = ( TotalTaskEntries - 2 ) then
  630.      BitBtn4.Enabled := false;
  631.     if CurrentTaskPointer > 1 then BitBtn3.Enabled := true;
  632.   end;
  633. end;
  634.  
  635. procedure TCCTaskBarForm.StartAsIcon1Click(Sender: TObject);
  636. begin
  637.   if StartingState = 0 then
  638.   begin
  639.     StartingState := 1;
  640.     StartAsIcon1.Checked := false;
  641.   end
  642.   else
  643.   begin
  644.     StartingState := 0;
  645.     StartAsIcon1.checked := true;
  646.   end;
  647.   WriteTheTaskBarIniFile;
  648. end;
  649.  
  650. procedure TCCTaskBarForm.ShowOnBottom1Click(Sender: TObject);
  651. begin
  652.   ShowPosition := 0;
  653.   ShowOnBottom1.Checked := true;
  654.   ShowOnTop1.Checked := false;
  655.   WriteTheTaskBarIniFile;
  656.   if Top = 1 then
  657.   begin
  658.     Top := Screen.Height - 90;
  659.   end;
  660. end;
  661.  
  662. procedure TCCTaskBarForm.ShowOnTop1Click(Sender: TObject);
  663. begin
  664.   ShowPosition := 1;
  665.   ShowOnBottom1.Checked := false;
  666.   ShowOnTop1.Checked := true;
  667.   WriteTheTaskBarIniFile;
  668.   if Top <> 1 then
  669.   begin
  670.     Top := 1;
  671.   end;
  672. end;
  673.  
  674. procedure TCCTaskBarForm.AddFile1Click(Sender: TObject);
  675. var ThePChar   ,
  676.     TheOtherPChar,
  677.     TheResultPChar : PChar;
  678.     TheExt  : String;
  679. begin
  680.   if TotalTaskEntries = 255 then
  681.   begin
  682.     MessageDlg( 'Maximum Taskbar Entries Reached!',mtError,[mbOk],0);
  683.     exit;
  684.   end;
  685.   GetMem( ThePChar , 255 );
  686.   if OpenDialog1.Execute then
  687.   begin
  688.     TotalTaskEntries := TotalTaskEntries + 1;
  689.     New( ThePTBArray[ TotalTaskEntries ] );
  690.     with ThePTBArray[ TotalTaskEntries ]^ do
  691.     begin
  692.       TheName := OpenDialog1.Filename;
  693.       TheBitmap := TBitmap.Create;
  694.       TheIcon := TIcon.Create;
  695.       TheBitmap.Height := 32;
  696.       TheBitmap.Width := 32;
  697.       TheExt := Uppercase( ExtractFileExt( TheName ));
  698.       if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  699.           ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  700.       begin
  701.         GetMem( TheOtherPChar , 255 );
  702.         GetMem( TheResultPChar , 255 );
  703.         StrPCopy( ThePChar, TheName );
  704.         StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  705.         if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  706.         begin
  707.           TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  708.         end
  709.         else
  710.         begin
  711.           MessageDlg( 'No Application Registered for this File Type!',mtError,[mbok],0);
  712.           TheIcon.Handle := 0;
  713.         end;
  714.         FreeMem( TheOtherPChar , 255 );
  715.         FreeMem( TheResultPChar , 255 );
  716.       end
  717.       else
  718.       begin
  719.         StrPCopy( ThePChar , TheName );
  720.         TheIcon := TIcon.Create;
  721.         TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  722.       end;
  723.       if TheIcon.Handle <> 0 then
  724.       begin
  725.         TheBitmap.Canvas.Draw( 1,1,TheIcon );
  726.       end
  727.       else
  728.       begin
  729.         TheBitmap.LoadFromFile( SaveStartupDir + '\Default.bmp' );
  730.       end;
  731.     end;
  732.     SetupTheTaskBar;
  733.   end;
  734.   FreeMem( ThePChar , 255 );
  735.   if TotalTaskEntries = 255 then AddFile1.Enabled := false;
  736. end;
  737.  
  738. procedure TCCTaskBarForm.NewFile1Click(Sender: TObject);
  739. begin
  740.   if ActiveButton = BitBtn5 then
  741.   begin
  742.     if TotalTaskEntries = 0 then exit;
  743.     Replacefile( CurrentTaskPointer );
  744.     SetUpTheTaskbar;
  745.     exit;
  746.   end;
  747.   if ActiveButton = BitBtn6 then
  748.   begin
  749.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  750.     Replacefile( CurrentTaskPointer + 1 );
  751.     SetUpTheTaskbar;
  752.     exit;
  753.   end;
  754.   if ActiveButton = BitBtn7 then
  755.   begin
  756.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  757.     Replacefile( CurrentTaskPointer + 2 );
  758.     SetUpTheTaskbar;
  759.     exit;
  760.   end;
  761. end;
  762.  
  763. procedure TCCTaskBarForm.Delete1Click(Sender: TObject);
  764. begin
  765.   if ActiveButton = BitBtn5 then
  766.   begin
  767.     if TotalTaskEntries = 0 then exit;
  768.     DeleteTasksFrom( CurrentTaskPointer );
  769.     AddFile1.Enabled := true;
  770.     SetUpTheTaskbar;
  771.     exit;
  772.   end;
  773.   if ActiveButton = BitBtn6 then
  774.   begin
  775.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  776.     DeleteTasksFrom( CurrentTaskPointer + 1 );
  777.     AddFile1.Enabled := true;
  778.     SetUpTheTaskbar;
  779.     exit;
  780.   end;
  781.   if ActiveButton = BitBtn7 then
  782.   begin
  783.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  784.     DeleteTasksFrom( CurrentTaskPointer + 2 );
  785.     AddFile1.enabled := true;
  786.     SetUpTheTaskbar;
  787.     exit;
  788.   end;
  789. end;
  790.  
  791. procedure TCCTaskBarForm.MoveUp1Click(Sender: TObject);
  792. var HoldingRecord : TBRecord;
  793. begin
  794.   if ActiveButton = BitBtn5 then
  795.   begin
  796.     if TotalTaskEntries = 0 then exit;
  797.     if CurrentTaskPointer = 1 then exit;
  798.     HoldingRecord := ThePTBArray[ CurrentTaskPointer - 1 ]^;
  799.     ThePTBArray[ CurrentTaskPointer - 1 ]^ :=
  800.      ThePTBArray[ CurrentTaskPointer ]^;
  801.     ThePTBArray[ CurrentTaskPointer ]^ := HoldingRecord;
  802.     SetUpTheTaskbar;
  803.     exit;
  804.   end;
  805.   if ActiveButton = BitBtn6 then
  806.   begin
  807.     If CurrentTaskPointer + 1 > TotalTaskEntries then exit;
  808.     HoldingRecord := ThePTBArray[ CurrentTaskPointer ]^;
  809.     ThePTBArray[ CurrentTaskPointer  ]^ :=
  810.      ThePTBArray[ CurrentTaskPointer + 1 ]^;
  811.     ThePTBArray[ CurrentTaskPointer + 1 ]^ := HoldingRecord;
  812.     SetUpTheTaskbar;
  813.     exit;
  814.   end;
  815.   if ActiveButton = BitBtn7 then
  816.   begin
  817.     if CurrentTaskPointer + 2 > TotalTaskEntries then exit;
  818.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 1 ]^;
  819.     ThePTBArray[ CurrentTaskPointer +  1 ]^ :=
  820.      ThePTBArray[ CurrentTaskPointer + 2 ]^;
  821.     ThePTBArray[ CurrentTaskPointer + 2 ]^ := HoldingRecord;
  822.     SetUpTheTaskbar;
  823.     exit;
  824.   end;
  825. end;
  826.  
  827. procedure TCCTaskBarForm.MoveDown1Click(Sender: TObject);
  828. var HoldingRecord : TBRecord;
  829. begin
  830.   if ActiveButton = BitBtn5 then
  831.   begin
  832.     if TotalTaskEntries = 0 then exit;
  833.     if CurrentTaskPointer = TotalTaskEntries then exit;
  834.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 1 ]^;
  835.     ThePTBArray[ CurrentTaskPointer + 1 ]^ :=
  836.      ThePTBArray[ CurrentTaskPointer ]^;
  837.     ThePTBArray[ CurrentTaskPointer  ]^ := HoldingRecord;
  838.     SetUpTheTaskbar;
  839.     exit;
  840.   end;
  841.   if ActiveButton = BitBtn6 then
  842.   begin
  843.     If CurrentTaskPointer + 1 >= TotalTaskEntries then exit;
  844.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 2 ]^;
  845.     ThePTBArray[ CurrentTaskPointer + 2 ]^ :=
  846.      ThePTBArray[ CurrentTaskPointer + 1 ]^;
  847.     ThePTBArray[ CurrentTaskPointer + 1 ]^ := HoldingRecord;
  848.     SetUpTheTaskbar;
  849.     exit;
  850.   end;
  851.   if ActiveButton = BitBtn7 then
  852.   begin
  853.     if CurrentTaskPointer + 2 >= TotalTaskEntries then exit;
  854.     HoldingRecord := ThePTBArray[ CurrentTaskPointer + 3 ]^;
  855.     ThePTBArray[ CurrentTaskPointer +  3 ]^ :=
  856.      ThePTBArray[ CurrentTaskPointer + 2 ]^;
  857.     ThePTBArray[ CurrentTaskPointer + 2 ]^ := HoldingRecord;
  858.     SetUpTheTaskbar;
  859.     exit;
  860.   end;
  861. end;
  862.  
  863. procedure TCCTaskBarForm.BitBtn5MouseDown(Sender: TObject;
  864.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  865. begin
  866.   ActiveButton := BitBtn5;
  867. end;
  868.  
  869. procedure TCCTaskBarForm.BitBtn6MouseDown(Sender: TObject;
  870.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  871. begin
  872.   ActiveButton := BitBtn6;
  873. end;
  874.  
  875. procedure TCCTaskBarForm.BitBtn7MouseDown(Sender: TObject;
  876.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  877. begin
  878.   ActiveButton := BitBtn7;
  879. end;
  880.  
  881. procedure TCCTaskBarForm.BitBtn5MouseUp(Sender: TObject;
  882.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  883. begin
  884.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  885.    BitBtn5.Left + 40 , CCTaskBarForm.Top + BitBtn5.Top - 40 );
  886. end;
  887.  
  888. procedure TCCTaskBarForm.BitBtn6MouseUp(Sender: TObject;
  889.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  890. begin
  891.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  892.    BitBtn6.Left + 40 , CCTaskBarForm.Top + BitBtn6.Top - 40 );
  893. end;
  894.  
  895. procedure TCCTaskBarForm.BitBtn7MouseUp(Sender: TObject;
  896.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  897. begin
  898.   if Button = mbRight then PopupMenu2.PopUp( CCTaskBarForm.Left +
  899.    BitBtn7.Left + 40 , CCTaskBarForm.Top + BitBtn7.Top - 40 );
  900. end;
  901.  
  902. end.
  903.